﻿namespace OOP
{
    using System;
    using System.ComponentModel;

    public class Battery
    {
        private const ushort MaxHoursIdle = 1000;
        private const ushort MaxHoursTalk = 300;
        private string model;
        private ushort? hoursIdle;
        private ushort? hoursTalk;
        private BatteryType type;

        public Battery() 
        {
        }

        public Battery(string model)
        {
            this.Model = model;
        }

        public Battery(string model, ushort hoursIdle, ushort hoursTalk, BatteryType type) : this(model)
        {
            this.HoursIdle = hoursIdle;
            this.HoursTalk = hoursTalk;
            this.Type = type;
        }

        public enum BatteryType
        {
            NiM1000, NiCd550, LIB1800, LiPo2400, [Description("Li-Ion")]LiIon = 4
        }

        public string Model
        {
            get
            {
                return this.model;
            }

            private set
            {
                if (value == null)
                {
                    throw new ArgumentNullException("The color is incorrect.");
                }
                else if (value.Length <= 0)
                {
                    throw new ArgumentOutOfRangeException("The color is incorrect.");
                }
                else
                {
                    this.model = value;
                }
            }
        }

        public ushort? HoursIdle
        {
            get
            {
                return this.hoursIdle;
            }

            private set
            {
                if (value > MaxHoursIdle)
                {
                    throw new ArgumentOutOfRangeException("Incorrect idle hours.");
                }
                else
                {
                    this.hoursIdle = value;
                }
            }
        }

        public ushort? HoursTalk
        {
            get
            {
                return this.hoursTalk;
            }

            private set
            {
                if (value > MaxHoursTalk)
                {
                    throw new ArgumentOutOfRangeException("Incorrect talk hours.");
                }
                else
                {
                    this.hoursTalk = value;
                }
            }
        }

        public BatteryType Type
        {
            get
            {
                return this.type;
            }

            private set
            {
                if ((value >= (BatteryType)4) || (value < (BatteryType)0))
                {
                    throw new ArgumentOutOfRangeException("Incorrect battery type.");
                }
                else if ((value != BatteryType.LIB1800) && (value != BatteryType.LiPo2400) && (value != BatteryType.NiCd550) && (value != BatteryType.NiM1000))
                {
                    throw new ArgumentOutOfRangeException("Incorrect battery type.");
                }
                else
                {
                    this.type = value;
                }
            }
        }

        public override string ToString()
        {
            return this.Model + Environment.NewLine + this.HoursIdle + Environment.NewLine + this.hoursTalk + Environment.NewLine + this.type;
        }
    }
}